//
//  MessageHistoryTableViewCell.swift
//  ezyform
//
//  Created by Hubert on 2022/5/9.
//  Copyright © 2022 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit

class MessageHistoryTableViewCell: UITableViewCell {
    let historyImageV: UIImageView = UIImageView()
    let titleL: BaseLabel = ContentLabel(R.font.interMedium(size: 15))
    let closeBtn: UIButton = UIButton()
    var closeClosure: (()->Void)?
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setUpviews()
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }
    override func layoutSubviews() {
        super.layoutSubviews()
    }
    func setUpviews(){
        self.selectionStyle = .none
        self.backgroundColor = .white

        //*************Section information
        historyImageV.image = UIImage.init(named: "message_search_history")
        self.contentView.addSubview(historyImageV)
        historyImageV.snp.makeConstraints { (make) in
            make.top.equalTo(15)
            make.bottom.equalTo(-15)
            make.left.equalTo(16)
            make.size.equalTo(CGSize(width: 16, height: 16))
        }
        
        //抗压缩能力最弱，容易被压缩
        titleL.setContentCompressionResistancePriority(.defaultLow, for: NSLayoutConstraint.Axis.horizontal)
        self.contentView.addSubview(titleL)
        titleL.snp.makeConstraints { make in
            make.left.equalTo(historyImageV.snp.right).offset(10)
            make.centerY.equalTo(historyImageV)
        }
        //close
        closeBtn.setImage(UIImage.init(named: "message_close"), for: .normal)
        closeBtn.addTarget(self, action: #selector(closeAction), for: .touchUpInside)
        self.contentView.addSubview(closeBtn)
        closeBtn.snp.makeConstraints { make in
            make.left.equalTo(titleL.snp.right)
            make.right.equalTo(-12)
            make.size.equalTo(CGSize(width: 40, height: 40))
            make.centerY.equalToSuperview()
        }
        
        let lineV = View(hexStr: Constant.SeparatorColorHexStr)
        self.contentView.addSubview(lineV)
        lineV.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.left.equalTo(titleL)
            make.right.equalTo(-20)
            make.height.equalTo(1)
        }
    }
    
    func setData(_ text: String) {
        self.titleL.text = text
    }
    
    @objc func closeAction() {
        self.closeClosure?()
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
